﻿using Game;

namespace Mekiasm.ElectricElement
{
    //燃煤发电机
    public class CoalGenerateElement : Common.ElectricElement
    {

        ComponentEnergyMachine machine;
        public CoalGenerateElement(int x, int y, int z) : base(x, y, z)
        {
            machine = Instance.Machine;

        }
        public override bool Simulate()
        {
            ChargeOrDischargeItem(0);
            var slot = machine.Slots[1];

            if (slot.Count > 0)
            {
                int v = slot.Value;
                var block = BlocksManager.Blocks[Terrain.ExtractContents(v)];
                int d = (int)block.GetFuelFireDuration(v) * 10;
                if (d > 0 && slot.FuelAmount + d <= slot.FuelCapacity)
                {
                    slot.FuelAmount += d;
                    slot.Count--;
                }
            }

            if (slot.FuelAmount > 0 && machine.Power + 1 <= machine.MaxPower)
            {
                slot.FuelAmount -= 1;
                machine.Power += 16;
            }

            machine.CraftProgress = slot.FuelAmount / (float)slot.FuelCapacity;

            return base.Simulate();
        }
    }
}
